package com.itbbfx.mapper;

import com.itbbfx.entity.Menu;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;

public interface MenuMapper extends Mapper<Menu> {
    @Select("select * from sys_menu")
    List<Menu> initRoleMenu();

    List<Menu> queryAllMenu(@Param("menu") Menu menu);

    int checkMenuHasChildren(@Param("id") Integer id);

    @Delete("delete from sys_menu where id=#{id}")
    int deleteMenu(@Param("id") Integer id);

    @Insert("insert into sys_menu(pid,title,href,spread,target,icon,available) " +
            "values(#{menu.pid},#{menu.title},#{menu.href},#{menu.spread},#{menu.pid}" +
            ",#{menu.icon},#{menu.available})")
    int addMenu(@Param("menu") Menu menu);

    @Update("update sys_menu set pid=#{menu.pid},title=#{menu.title},href=#{menu.href}," +
            "spread=#{menu.spread},target=#{menu.target},icon=#{menu.icon}," +
            "available=#{menu.available} where id=#{menu.id}")
    int updateMenu(@Param("menu") Menu menu);

    @Select("select count(1) from sys_role_menu rm,sys_role r where rm.mid=r.roleid and rm.mid=#{id}")
    int queryRoleMenu(@Param("id") Integer id);

    @Delete("delete from sys_role_menu where mid=#{id}")
    int deleteRoleMenu(@Param("id") Integer id);
}